package com.action.calculator;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

// Simple CalculatorActivity Class extends the inbuilt Android Activity 
public class CalculatorActivity extends Activity implements OnClickListener {

	private TextView answerText;
	private Button onePlusOneButton;
	private Button onePlusTwoButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// The savedInstanceState can be ignored, this is used for saving state
		// in your application if your app is minimised, there is no state
		// needed in this application
		super.onCreate(savedInstanceState);

		// This sets the UI you will be using for this Activity
		this.setContentView(R.layout.calculator_activity);

		getViewsById();
		setupListeners();

	}

	private void setupListeners() {
		onePlusOneButton.setOnClickListener(this);
		onePlusTwoButton.setOnClickListener(this);

	}

	private void getViewsById() {
		// This finds the TextView on the R.layout.calculator_activity and
		// returns a reference to it
		answerText = (TextView) findViewById(R.id.answer);
		onePlusOneButton = (Button) findViewById(R.id.button1);
		onePlusTwoButton = (Button) findViewById(R.id.button2);

	}

	@Override
	public void onClick(View button) {
		switch (button.getId()) {
		case R.id.button1:
			answerText.setText("ANS = 2");
			break;
		case R.id.button2:
			answerText.setText("ANS = 3");
			break;

		}

	}
}
